<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .current{
            background-color: aqua;
        }
    </style>
</head>
<body>
    <ul>
        <li>灌篮高手</li>
        <li>魔神坛斗士</li>
        <li>圣斗士星矢</li>
        <li class="current">棋魂</li>
        <li>浪客剑心</li>
        <li>麻辣教师</li>
        <li>灌篮高手</li>
    </ul>
    <button onclick = "addNode()">添加</button>
    <button onclick = "removeNode()">删除</button>

    <button onclick = "rep()">替换节点</button>

    <script>
        let ul = document.querySelector("ul")
        function addNode (){
            var li = document.createElement("li");
            li.innerHTML = "熊出没";
            //在父元素的末尾添加元素
            ul.append(li);

            var li2 = document.createElement("li");
            li2.innerHTML="足球小将";
            ul.prepend(li2);
        }

        //移除操作
        function removeNode(){
            let removeObject  =document.querySelector(".current");
            //移除，元素在dom中已经没有了
            // if(removeObject) {
            //     removeObject.remove()
            // }
            //隐藏，但是元素还在
            removeObject.style.display="none"
        }

        //替换节点
        function rep(){
            let removeObject  =document.querySelector(".current");
            let newObject = document.createElement("li");
            newObject.innerHTML="魔神英雄坛";
            //方法调用者是父节点
            removeObject.parentElement.replaceChild(newObject,removeObject);
        }


    </script>
</body>
</html>